//    Copyright (C) Kherty.  All rights reserved.
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Parsing
{
    class MCSymbolCreator : TokenCreator
    {
        public MCSymbolCreator(MCSymbol s)
        {
            MCSymbol = s;
            MatchString = s.String();
            Contract.Assert(MatchString.Length <= 3, MatchString + " is too big for a match");
            matchSize = MatchString.Length;
        }

        readonly int matchSize;
        public override int MatchSize()
        {
            return matchSize;
        }

        readonly MCSymbol MCSymbol;
        readonly string MatchString;
        public override char[] FirstChars()
        {
            return new char[] { MatchString[0] };
        }
        public override Token Match(Lexer l)
        {
            for (int i = 0; i < matchSize; i++)
            {
                if (MatchString[i] != l[i + l.Position])
                    return null;
            }
            return MCSymbol.Create();
        }
    }
}